
package com.erp.common.voucher.util;

import com.framework.util.JedisUtil;
import com.framework.util.RedisUtil;

/**
 * @description
 * @date 2020年8月14日
 * @author dongbin
 * 
 */
public class FinVoucherUtil {
    
    //初始化凭证流水号（根据凭证字）
    public static void setVoucherNumberCache(String voucherType, Long voucherNumber) {
        String cacheKey = "GLOBAL_VOUCHER_NUMBER_"+voucherType.toUpperCase();
        RedisUtil.set(cacheKey, voucherNumber.toString());
    }
    
    //增加凭证流水号（根据凭证字）
    public static Long incrVoucherNumberCache(String voucherType) {
        String cacheKey = "GLOBAL_VOUCHER_NUMBER_"+voucherType.toUpperCase();
        return JedisUtil.getJedis().incr(cacheKey);
    }
    
    //获取凭证流水号（根据凭证字）
    public static Long getVoucherNumberCache(String voucherType) {
        String cacheKey = "GLOBAL_VOUCHER_NUMBER_"+voucherType.toUpperCase();
        String value = RedisUtil.get(cacheKey);
        try {
            if(value!=null) {
                return Long.valueOf(value);
            }
        }catch(Exception e) {
            
        }
        
        return -1L;
    }
    

}
